﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Wilson/MP/Base.Master" AutoEventWireup="true" CodeBehind="ProEdit.aspx.cs" Inherits="WebsiteAdmin.Wilson.ProInfo.ProEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head_Title" runat="server">编辑产品——产品</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Head_Meta" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Head_Css" runat="server">
    <link rel='stylesheet' type='text/css' href='/css/datepicker_vista/datepicker_vista.css' />
    <style type="text/css">
    div.hide{ display:none;}

		#Dialog {
			position: absolute; 
			z-index: 1000; 
			display: none;
			width: 600px;
			background: #FFFFFF;
			border: 3px #999999 solid; 
		}
		#Dialog h6 {
			width: 580px;
			height: 20px;
			line-height: 20px;
			margin: 0;
			padding: 5px 10px; 
			background: #EFEFEF;
			text-align: right; 
			
		}
		#Dialog div.box {
			width: 600px;
			max-height:500px;
			overflow-y:scroll;
		}
		
		#Dialog div#DialogHtml
		{
		    width: 560px;
			padding: 10px; 
			color: #999;
		}
		
		#DialogHtml a {
			float: left;
			height: 20px; 
			line-height: 20px; 
			margin: 5px 15px 5px 0;
			white-space: nowrap;
		}
		
		#DialogHtml h4{ clear:both; background-color:#efefef; font-size:13px; margin-top:5px; display:block; height: 20px; 
			line-height: 20px; padding:5px;}
		
		#DialogHtml b{ float:left; clear:left; height: 20px; 
		    background-color:#efefef;
			line-height: 20px; 
			margin: 3px 15px 3px 0;
			padding:2px;
			white-space: nowrap;
		}
        #DialogHtml h4 a,#DialogHtml b a{ margin: 0;}	
	</style>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Head_Script" runat="server">
    <script src="../../Script/Mootools.Smoothbox.js" type="text/javascript"></script>
    <script src="../../CKEditor/CKEditor.js" type="text/javascript"></script>
    <script src="../../CKFinder/CKFinder.js" type="text/javascript"></script>
	<script type="text/javascript" src="/Script/datepicker.js"></script>
	<script type="text/javascript" language="javascript">
        var MenuViewID = 2;
        Array.implement({
            getFirstRadio: function() {
                if (this.length == 0) {
                    return null;
                }
                return this[0];
            }
        });
        window.addEvent('domready', function() {
            if (typeof (CKEDITOR) == 'undefined' || typeof (CKFinder) == 'undefined') {
                alert('加载CKEditor或CKFinder失败');
            } else {
                CKFinder.setupCKEditor(null, '/CKFinder/');
                CKEDITOR.replace('txbProContent');
            }

            $('submitbtn').addEvent('click', function() {
                Submit();
            });
            
            $('ShowLink').addEvent('click', function() {
                BrowseServer('Images:/Product/', 'txbMainImgURL', 'ShowView');
            });
            $('mediumImgLink').addEvent('click', function() {
                BrowseServer('Images:/Product/', 'txbMediumImgURL', 'mediumImg');
            });
            $('bigImgLink').addEvent('click', function() {
                BrowseServer('Images:/Product/', 'txbBigImgURL', 'bigImg');
            });
            
            $('selCatList').set('value',<%=catID %>);
            SerSelect();
            $('selSerList').set('value',<%=serID %>);
            
            new DatePicker($('txbDateStart'), {
                pickerClass: 'datepicker_vista',
                format: 'Y-m-d',
                inputOutputFormat: 'Y-m-d',
                yearPicker: false,
                allowEmpty: false,
                toggleElements: $('CalendarTrigger2')
            });
            new DatePicker($('txbDateEnd'), {
                pickerClass: 'datepicker_vista',
                format: 'Y-m-d',
                inputOutputFormat: 'Y-m-d',
                yearPicker: false,
                allowEmpty: false,
                toggleElements: $('CalendarTrigger3'),
                onSelect: function(d) {
                    var startD = $('txbDateStart').get('value');
                    var dd = d.diff(startD) + 1;
                    if (dd < 0) {
                        $('txbDateEnd').getNext('i').set('text', '相隔 ' + (-dd) + ' 天');
                    }
                    else {
                        alert('日期至少相隔1天');
                        $('txbDateEnd').getNext('i').set('text', '');
                    }
                }
            });
            var proReNum = <%=proReNum %>;
            if(proReNum == '1')
            {
                $('rdoRe').setProperty('checked','checked');
                $('trProRe').setStyle('display', '');
            }else
            {
                $('rdoNotRe').setProperty('checked','checked');
                $('trProRe').setStyle('display', 'none');
            }
            
            $('rdoNotRe').addEvent('click', function() {
                $('trProRe').setStyle('display', 'none');
            });
            $('rdoRe').addEvent('click', function() {
                $('trProRe').setStyle('display', '');
            });
            
        });
        
        function SetFileField(fileUrl, data) {
            $(data["selectActionData"]).value = fileUrl;
            $(this).setProperty('src', fileUrl);
        }
        function BrowseServer(startupPath, functionData, element) {
            var finder = new CKFinder();
            finder.startupPath = startupPath;
            finder.selectActionData = functionData;
            finder.selectActionFunction = SetFileField.bind(element);
            finder.popup();
        }

        function SerSelect() {
            var optNum = $('selSerList').length;
            for (var i = 0; i < optNum; i++) {
                $('selSerList').remove('option');
            }
            var txbCatID = $('selCatList').get('value');
            if (!isNaN(txbCatID)) {
                new Request.JSON({
                    method: 'post',
                    url: 'Handler/SerList.ashx',
                    data: {
                        CatID: txbCatID
                    },
                    noCache: true,
                    onSuccess: function(data, text) {
                        if (data.Title != '0') { 
                           for(var i=0;i<data.List.length;i++)
                           {
                               var myElement = new Element('option', { value: data.List[i].PKID });
                               myElement.appendText(data.List[i].SeriesName);
                               myElement.inject($('selSerList'));
                           }
                        }
                        else
                        {
                            alert('该分类下无系列');
                            LightBox.remove();
                        }
                    },
                    onFailure: function(xhr) {
                        alert(xhr.statusText);
                        LightBox.remove();
                    }
                }).send();  
            }
            else {
                alert('请先选择分类');
            }
        }

        function getContents(e) {
	        var oEditor = CKEDITOR.instances[e];
	        if (oEditor != null) {
		        return(oEditor.getData());
	        } else {
		        return "";
	        }
	    }
        
        function Submit() {
            var txbCatID = $('selCatList').get('value').trim().toInt();
            if (isNaN(txbCatID)) {
                alert('请选择产品分类');
                return false;
            }
            var txbSerID = $('selSerList').get('value').trim().toInt();
            if (isNaN(txbSerID)) {
                alert('请选择产品系列');
                return false;
            }
            
            var txbProName = $('txbProName').get('value').trim();
            if (txbProName.length == 0) {
                alert('产品标题错误');
                return false;
            }
            var txbProTypeNum = $('txbProTypeNum').get('value').trim();
            var txbKeywords = $('txbKeywords').get('value').trim();
            var txbSummary = $('txbSummary').get('value').trim();
            var txbDescription = $('txbDescription').get('value').trim();
            var txbPackInfo = $('txbPackInfo').get('value').trim();
            var txbProCode = ''; //$('txbProCode').get('value').trim();
            //if (txbProCode.length == 0) {
            //    alert('请输入产品显示链接');
            //    return false;
            //}
            var txbMainImgURL  = $('txbMainImgURL').get('value').trim();
            var txbMediumImgURL  = $('txbMediumImgURL').get('value').trim();
            var txbBigImgURL  = $('txbBigImgURL').get('value').trim();
            
            var txbProContent = getContents('txbProContent').trim();
            if (txbProContent.length == 0) {
                alert('请输入产品介绍');
                return false;
            }
            
            var txbSortOrder = $('txbSortOrder').get('value').trim().toInt();
            if (isNaN(txbSortOrder)) {
                alert('必须是整数');
                return false;
            }
            
            //0:不推荐   1：推荐
            var proReNum = 0;
            if ($('rdoRe').getProperty('checked') == true) {
                proReNum = 1;
            }
            var startDate = $('txbDateStart').value;
            if(startDate == null|| startDate =='')
            {
                //debugger;
                var date = new Date();
                startDate = date.getFullYear()+"-"+date.getUTCMonth()+"-"+date.getUTCDay();
            }
		    var endDate = $('txbDateEnd').value;
            
            Update(txbCatID,txbSerID,txbProName,txbProTypeNum,txbKeywords,txbSummary,txbDescription,
                    txbProCode,txbMainImgURL,txbMediumImgURL,txbBigImgURL,txbProContent, txbSortOrder,txbPackInfo,proReNum,startDate,endDate);
        }
        
        function Update(txbCatID,
                        txbSerID,
                        txbProName,
                        txbProTypeNum,
                        txbKeywords,
                        txbSummary,
                        txbDescription,
                        txbProCode,
                        txbMainImgURL,
                        txbMediumImgURL,
                        txbBigImgURL,
                        txbProContent,
                        txbSortOrder,
                        txbPackInfo,proReNum,startDate,endDate
            ) {

            new Request.JSON({
                method: 'post',
                url: 'Handler/ProUpdate.ashx',
                data: {
                    PKID:<%=pkid %>,
                    CatID: txbCatID,
                    SerID: txbSerID,
                    ProName : txbProName,
                    ProTypeNum:txbProTypeNum,
                    Keywords : txbKeywords,
                    Summary:txbSummary,
                    Description: txbDescription,
                    ProCode : txbProCode,
                    MainImgURL : txbMainImgURL,
                    MediumImgURL:txbMediumImgURL,
                    BigImgURL:txbBigImgURL,
                    ProContent : txbProContent,
                    SortBy: txbSortOrder,
                    PackInfo:txbPackInfo,
                    ProReNum: proReNum,
                    StartDate: startDate,
                    EndDate:endDate
                    
                },
                noCache: true,
                onSuccess: function(data, text) {
                    if (data.Done == 'Success') { 
                        
                        if(confirm('修改成功，返回列表？'))
                        {
                            document.location.href = '/Wilson/ProInfo/ProList.aspx';
                        };
                        LightBox.remove();
                    }
                    else
                    {
                        alert('修改失败');
                        LightBox.remove();
                    }
                },
                onFailure: function(xhr) {
                    alert(xhr.statusText);
                    LightBox.remove();
                }
            }).send();
        }
</script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Body_Top" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Body_Content" runat="server">
    <div class="infobox">
        <h3>
        <span>产品编辑</span>
			<a href="/Wilson/ProInfo/ProList.aspx" class="back action">返回产品列表</a>
        </h3>
        <div class="mt10">
        <form id="myForm" action="">
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
		        <tr>
            		<td align="right" width="100"><span class="Need">所属分类：</span></td>
            		<td>
            		    <select id="selCatList" onchange="javascript:SerSelect();">
            		        <asp:Repeater ID="repCatList" runat="server" EnableViewState="false">
            		            <ItemTemplate>
            		                <option value="<%#Eval("PKID") %>"><%#Eval("CatName") %></option>
            		            </ItemTemplate>
            		        </asp:Repeater>
            		    </select>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">所属系列：</span></td>
            		<td>
            		    <select id="selSerList">
            		    </select>
            		</td>
				</tr>
		        
		        <tr>
            		<td align="right" width="100"><span class="Need">产品名称：</span></td>
            		<td>
            			<input name="txbProName" type="text" id="txbProName"  maxlength="40" size="40" style="width:300px;" value="<%=proName %>" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">产品型号：</span></td>
            		<td>
            			<input name="txbProTypeNum" type="text" id="txbProTypeNum"  maxlength="40" size="40" style="width:300px;" value="<%=proTypeNum %>" />
            		</td>
				</tr>
				<!--<tr>
            		<td align="right" width="100"><span class="Need">显示链接：</span></td>
            		<td>
            			<input name="txbProCode" type="text" id="txbProCode" maxlength="20" size="20" value="<%=proCode %>" /><i>.html
            			限20个字符，例 service、fuwu</i>
            		</td>
				</tr>-->
				<tr>
            		<td align="right" width="100">关键词：</td>
            		<td>
            			<input name="txbKeywords" type="text" id="txbKeywords" maxlength="50" size="50" value="<%=keywords %>" />
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">商品简介：</span></td>
            		<td>
            			<textarea name="txbSummary" rows="3" cols="20" id="txbSummary"><%=summary%></textarea>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">商品信息：</span></td>
            		<td>
            			<textarea name="txbDescription" rows="3" cols="20" id="txbDescription"><%=description %></textarea>
            		</td>
				</tr>
				<tr>
            		<td align="right" width="100"><span class="Need">包装信息：</span></td>
            		<td>
            			<textarea name="txbPackInfo" rows="3" cols="20" id="txbPackInfo"><%=packInfo %></textarea>
            		</td>
				</tr>
				<!--列表图 开始-->
				<tr>
                    <td align="right" width="100">
                        160 x 160图片：</td>
                    <td>
                           <input type="text" id="txbMainImgURL" name="txbMainImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly" value="<%=mainImgURL %>"  /> <font color="red">*&nbsp;</font>
                           <a id="ShowLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:160px; height:160px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="ShowView" alt="" src="<%=mainImgURL %>" />
                        </div>
                        <i>图片尺寸 160 x 160。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
                <!--列表图 结束-->
                <!--产品页主图 开始-->
                <tr>
                    <td align="right" width="100">
                        400 x 400图片：</td>
                    <td>
                           <input type="text" id="txbMediumImgURL" name="txbMediumImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly" value="<%=mediumImgURL %>"  /> <font color="red">*&nbsp;</font>
                           <a id="mediumImgLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:400px; height:400px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="mediumImg" alt="" src="<%=mediumImgURL %>" />
                        </div>
                        <i>图片尺寸 400 x 400。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
                <!--产品页主图 结束-->
                <!--产品页放大图 开始-->
                <tr>
                    <td align="right" width="100">
                        800 x 800图片：</td>
                    <td>
                           <input type="text" id="txbBigImgURL" name="txbBigImgURL" style="width:450px; color:#666; background-color:#efefef; border:1px #ccc solid;" readonly="readonly" value="<%=bigImgURL %>"  /> <font color="red">*&nbsp;</font>
                           <a id="bigImgLink" style="cursor:pointer;cursor:hand;border:solid 1px;padding:0 10px 0 10px;">浏览</a>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="100">&nbsp;</td>
                    <td>
                        <div style=" width:400px; height:400px; overflow:hidden; border:1px #999 solid; background-color:#f8f8f8; clear:both;">
                           <img id="bigImg" alt="" src="<%=bigImgURL %>" />
                        </div>
                        <i>图片尺寸 800 x 800(此处显示400x400)。</i><br />
                        <i>如果图片不能完全填充，请重新选择图片。</i>
                    </td>
                </tr>
                <!--产品页放大图 结束-->
				<tr>
            		<td align="right" width="100"><span class="Need">显示排序：</span></td>
            		<td>
            			<input name="txbSortOrder" type="text" id="txbSortOrder" maxlength="2" size="5" value="<%=sortBy %>" />
            			<i>请输入数字</i>
            		</td>
				</tr>
							
				<tr>
					<td align="right"><span class="Need">产品介绍：</span></td>
					<td>
						<textarea name="txbProContent" rows="14" cols="20" id="txbProContent"><%=proContent%></textarea>
						<i>限2000汉字(4000字符)</i>
					</td>
				</tr>
				<tr>
                    <td align="right"><span class="Need">推荐：</span></td>
                    <td>
                        <input type="radio" id="rdoNotRe" name="ProRe" value="1" class="ProRe" />不推荐　　
                        <input type="radio" id="rdoRe" name="ProRe" value="2" class="ProRe" />推荐
                    </td>
                </tr>
                <tr style="display:none;" id="trProRe">
                    <td align="right"><span class="Need">日期：</span></td>
                    <td>
                        <input name="txbDateStart" type="text" id="txbDateStart" maxlength="50" value="<%=startDate %>" readonly="readonly" />
			            <img alt="" src="../../css/datepicker_vista/calendar.gif" id="CalendarTrigger2" />
			            -
			            <input name="txbDateEnd" type="text" id="txbDateEnd" maxlength="50" value="<%=endDate %>"  readonly="readonly" />
			            <img alt="" src="../../css/datepicker_vista/calendar.gif" id="CalendarTrigger3" />
			            <i></i>
                    </td>
                </tr>
		    </table>
		    <table border="0" cellpadding="0" cellspacing="0" class="table_form">
				<tr>
					<td width="100" height="40">&nbsp;</td>
					<td>
						<input id="submitbtn" type="button" value="提交" class="btn" />
						<input type="reset" value="重置" class="btn" />
					</td>
				</tr>
			</table>
		</form>
        </div>
    </div>
    <div style="display:none;">
        <label id="lblStartDate"><%=startDate %></label>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="Body_Foot" runat="server">
</asp:Content>
